__author__ = 'mars'
import os
import oss2
import time

auth = oss2.Auth('LTAIlZDnMMaobPYs', 'AVYnmSEtQ3zs62ASgQ10HYaumf8nHc ')
service = oss2.Service(auth, 'http://oss-cn-shanghai.aliyuncs.com')

print([b.name for b in oss2.BucketIterator(service)])


access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', 'LTAIAqgrg0qh5QIa')
access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', 'bowrqEK0na3HCNFDyWWYU3xLqWgdoH')
bucket_name = os.getenv('OSS_TEST_BUCKET', 'backupbluk001')
endpoint = os.getenv('OSS_TEST_ENDPOINT', 'http://oss-cn-shanghai.aliyuncs.com')

for param in (access_key_id, access_key_secret, bucket_name, endpoint):
    assert '<' not in param, 'abc' + param


bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)

bucket.put_object_from_file("mars1/test2233.txt", "D://11111//test.txt")

path1="F:\\sqlbak\\BJCG2011"
for f in os.listdir(path1):
    file= path1 + os.sep + f

    lastmtime = os.stat(file).st_ctime

    now1 = time.time() - lastmtime
    if now1 < 86400:
        print now1
        print file
        print lastmtime
        bucket.put_object_from_file(f,file
                                   )
        print 'upload ok'

    if now1 > 290000:
        print file
        os.remove(file)
        print file + 'removed'